package com.citywithincity.api.post.impl;

import java.io.IOException;
import java.util.Map;

import com.citywithincity.api.post.ApiPost;
import com.citywithincity.api.post.ApiResponse;
import com.citywithincity.utils.HttpUtil;
import com.citywithincity.utils.JsonUtil;

public class JsonApiPost implements ApiPost {

	private String baseUrl;
	
	public JsonApiPost(String baseUrl){
		this.baseUrl = baseUrl;
	}
	
	@Override
	public ApiResponse post(String api, Map<String, Object> args, int crypt) throws IOException {
		
		String content = HttpUtil.rawPost(baseUrl + api, JsonUtil.toJson(args));
		Map<String, Object> result = JsonUtil.read(content);
		return new ApiResponse(result);
	}

}
